package com.natasha.pins.data.bean;

import java.sql.Date;
import java.text.ParseException;
import java.text.SimpleDateFormat;

import android.database.Cursor;
import android.util.Log;

import com.natasha.pins.util.Constants;

public class PinsMasterBean {
	
	//SQL variables
	public static final String NAME_PINS_MASTER = "PINS_MASTER";
	public static final String NAME_PMUSER = "PMUSER";
	public static final String NAME_PMID = "_id";
	public static final String NAME_PMWHENDT = "PMWHENDT";
	public static final String NAME_PMTITLE = "PMTITLE";
	public static final String NAME_PMDETAIL = "PMDETAIL";
	public static final String NAME_PMISFAV = "PMISFAV";
	public static final String NAME_PMMEDIA = "PMMEDIA";

	//SQL queries
	public static final String QRY_CREATE_PINS_MASTER = "CREATE TABLE PINS_MASTER("
			+ NAME_PMUSER  + " TEXT NOT NULL,"
			+ NAME_PMID + " INTEGER PRIMARY KEY AUTOINCREMENT,"
			+ NAME_PMWHENDT + " TEXT NOT NULL,"
			+ NAME_PMTITLE  + " TEXT NOT NULL,"
			+ NAME_PMDETAIL + " TEXT,"
			+ NAME_PMISFAV + " INTEGER,"
			+ NAME_PMMEDIA + " TEXT);";
	public static final String QRY_DROP_PINS_MASTER = "DROP TABLE PINS_MASTER;";
			
	//Bean variables
	private String pmuser;
	private int pmid;
	private Date pmwhendt;
	private String pmtitle;
	private String pmdetail;
	private int pmisfav;
	private String pmmedia;

	public PinsMasterBean() {
	}
	
	public PinsMasterBean(String pmuser, int pmid, Date pmwhendt,
			String pmtitle, String pmdetail, int pmisfav, String pmmedia) {
		super();
		this.pmuser = pmuser;
		this.pmid = pmid;
		this.pmwhendt = pmwhendt;
		this.pmtitle = pmtitle;
		this.pmdetail = pmdetail;
		this.pmisfav = pmisfav;
		this.pmmedia = pmmedia;
	}
	
	public PinsMasterBean(Cursor cursor) {
		super();
		
		java.util.Date date = null;
		
		this.pmid = cursor.getInt(cursor.getColumnIndexOrThrow(PinsMasterBean.NAME_PMID));
		this.pmuser = cursor.getString(cursor.getColumnIndexOrThrow(PinsMasterBean.NAME_PMUSER));
		
		SimpleDateFormat dateTimeFormat = new SimpleDateFormat(Constants.DATE_TIME_FORMAT);
		
		try{
			String dateString = cursor.getString(cursor.getColumnIndexOrThrow(PinsMasterBean.NAME_PMWHENDT));
			date = dateTimeFormat.parse(dateString);
			this.pmwhendt = new Date(date.getTime());
		}catch(ParseException e){
			Log.e(this.getClass().getName(), e.getMessage(), e);
		}
		
		this.pmtitle = cursor.getString(cursor.getColumnIndexOrThrow(PinsMasterBean.NAME_PMTITLE));
		this.pmdetail = cursor.getString(cursor.getColumnIndexOrThrow(PinsMasterBean.NAME_PMDETAIL));
		this.pmmedia = cursor.getString(cursor.getColumnIndexOrThrow(PinsMasterBean.NAME_PMMEDIA));
		this.pmisfav = cursor.getInt(cursor.getColumnIndexOrThrow(PinsMasterBean.NAME_PMISFAV));
	}
	
	public String getPmuser() {
		return pmuser;
	}
	public void setPmuser(String pmuser) {
		this.pmuser = pmuser;
	}
	public int getPmid() {
		return pmid;
	}
	public void setPmid(int pmid) {
		this.pmid = pmid;
	}
	public Date getPmwhendt() {
		return pmwhendt;
	}
	
	public String getStringPmwhendt() {
		SimpleDateFormat dateTimeFormat = new SimpleDateFormat(Constants.DATE_TIME_FORMAT);
		String dateString = dateTimeFormat.format(getPmwhendt());
		return dateString;
	}
	
	public void setPmwhendt(Date pmwhendt) {
		this.pmwhendt = pmwhendt;
	}
	public String getPmtitle() {
		return pmtitle;
	}
	public void setPmtitle(String pmtitle) {
		this.pmtitle = pmtitle;
	}
	public String getPmdetail() {
		return pmdetail;
	}
	public void setPmdetail(String pmdetail) {
		this.pmdetail = pmdetail;
	}
	public int getPmisfav() {
		return pmisfav;
	}
	public void setPmisfav(int pmisfav) {
		this.pmisfav = pmisfav;
	}
	public String getPmmedia() {
		return pmmedia;
	}
	public void setPmmedia(String pmmedia) {
		this.pmmedia = pmmedia;
	}

	public String toString(){   
        StringBuffer buff = new StringBuffer();
        buff.append(this.getClass().getName());
        buff.append("[pmuser = " + getPmuser() + "]");
		buff.append("[pmid = " + getPmid() + "]");
		buff.append("[pmwhendt = " + getPmwhendt() + "]");
		buff.append("[pmtitle = " + getPmtitle() + "]");
		buff.append("[pmdetail = " + getPmdetail() + "]");
		buff.append("[pmisfav = " + getPmisfav() + "]");
		buff.append("[pmmedia = " + getPmmedia() + "]");
		
		return buff.toString();
    }
}
